package controller;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Component;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import pojo.Customer;
import service.CustomerService;

@Controller
public class CustomerController {

	@Resource(name="service")
	private CustomerService cs;
	
	@RequestMapping(value="/addCustomer",method=RequestMethod.POST,consumes="application/json")
	@ResponseBody
	public Customer addCustomer(@RequestBody Customer c){
		return cs.addCustomer(c);
	}
	
	@RequestMapping(value="/updateCustomer",method=RequestMethod.PUT,consumes="application/json")
	@ResponseBody
	public Customer updateCustomer(@RequestBody Customer c){
		System.out.println(c.getCname());
		return cs.updateCustomer(c);
	}
	
	@RequestMapping(value="/deleteCustomer",method=RequestMethod.DELETE)
	@ResponseBody
	public String deleteCustomer(String id){
		return cs.deleteCustomer(id);
	}
	
	@RequestMapping(value="/findAllCustomers",method=RequestMethod.GET)
	@ResponseBody
	public List<Customer> deleteCustomer(){
		return cs.findAllCustomers();
	}
}
